import math
import random
import sys

#global "constants"
MIN_CHAR = ord(' ')
MAX_CHAR = ord('~')
PAD_LENGTH = 4096

    
def rotDecipher(mssg,pad):
    count =0
    Demssg=[0]*len(mssg)
    message=""
    for i in range(0, len(mssg)):
        tempC=ord(mssg[i])-pad[count]
        count+=1
        while tempC<MIN_CHAR:
            tempC=MAX_CHAR-(MIN_CHAR-tempC)#wrapping
        message+=chr(tempC)
        if count == len(pad):
            count=0
    print "Decrpyted Message:",message
    return message
    
def rotCipher(mssg, pad):
    count =0
    Enmssg=[0]*len(mssg)
    for i in range(0, len(mssg)):
        Enmssg[i]=chr(ord(mssg[i])+pad[count])
        count+=1
        if ord(Enmssg[i])>MAX_CHAR:
            Enmssg[i]=chr(MIN_CHAR+(ord(Enmssg[i])-MAX_CHAR))#wrapping
        if count == len(pad):
            count=0
    print "Encrypted Message:", Enmssg
    return Enmssg

def genPad(length):
    pad=[0]*length
    for i in range(0, length):
        pad[i]=random.randint(MIN_CHAR, MAX_CHAR)#printable characters

    return pad

mssg=raw_input("Enter a message: ")
pad=genPad(PAD_LENGTH)
encryptedMsg=rotCipher(mssg, pad)
rotDecipher(encryptedMsg, pad)
